// TerrainHolePanel.cpp : implementation file
//

#include "stdafx.h"
#include "TerrainHolePanel.h"
#include "TerrainHoleTool.h"

/////////////////////////////////////////////////////////////////////////////
// CTerrainHolePanel dialog


CTerrainHolePanel::CTerrainHolePanel(CTerrainHoleTool *tool,CWnd* pParent /*=NULL*/)
	: CXTResizeDialog(CTerrainHolePanel::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTerrainHolePanel)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	assert( tool != 0 );
	m_tool = tool;
	Create( IDD,pParent );
}


void CTerrainHolePanel::DoDataExchange(CDataExchange* pDX)
{
	CXTResizeDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTerrainHolePanel)
	DDX_Control(pDX, IDC_RADIUS, m_radius);
	DDX_Control(pDX, IDC_HOLE_REMOVE, m_removeHole);
	DDX_Control(pDX, IDC_HOLE_MAKE, m_makeHole);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTerrainHolePanel, CXTResizeDialog)
	//{{AFX_MSG_MAP(CTerrainHolePanel)
	ON_BN_CLICKED(IDC_HOLE_MAKE, OnHoleMake)
	ON_BN_CLICKED(IDC_HOLE_REMOVE, OnHoleRemove)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_RADIUS, OnReleasedcaptureRadius)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTerrainHolePanel message handlers

void CTerrainHolePanel::OnHoleMake() 
{
	SetMakeHole(true);
	m_tool->SetMakeHole(true);
}

void CTerrainHolePanel::OnHoleRemove() 
{
	SetMakeHole(false);
	m_tool->SetMakeHole(false);
}

BOOL CTerrainHolePanel::OnInitDialog() 
{
	CXTResizeDialog::OnInitDialog();
	
	//m_makeHole.SetPushedBkColor( STD_PUSHED_COLOR );
	//m_removeHole.SetPushedBkColor( STD_PUSHED_COLOR );
	
	m_makeHole.SetCheck(m_tool->GetMakeHole());
	m_removeHole.SetCheck(!m_tool->GetMakeHole());

	float fMax=100;
	m_radius.SetRange( 1,100 * log10(fMax) );	
	SetRadius();

	SetResize(IDC_HOLE_MAKE, SZ_HORRESIZE(0.5f));
	SetResize(IDC_HOLE_REMOVE, CXTResizeRect(0.5f, 0.0f, 1.0f, 0.0f));
	SetResize(IDC_RADIUS, SZ_HORRESIZE(1.0f));

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTerrainHolePanel::SetRadius( )
{
	m_radius.SetPos( log10(m_tool->GetBrushRadius()/0.5f)*100.0f );
}

void CTerrainHolePanel::OnReleasedcaptureRadius(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int radius = pow(10.0f,m_radius.GetPos()/100.0f);
	m_tool->SetBrushRadius(radius*0.5f);
	*pResult = 0;
}

void CTerrainHolePanel::SetMakeHole( bool bEnable )
{
	if (bEnable)
	{
		m_makeHole.SetCheck(1);
		m_removeHole.SetCheck(0);
	}
	else
	{
		m_makeHole.SetCheck(0);
		m_removeHole.SetCheck(1);
	}
}